<?php
if (!defined('IN_WONDERSHARE'))
{
	die('Hacking attempt');
}
require('./classes/module/module_product_attributes.php');
class ProductAttributesControl
{
	var $product_attributes_m;
	function __construct()
	{
		$this->product_attributes_m = new ProductAttributesModule();
	}
	/**
	* 得到分页相关信息
	*
	* @param   int        $page             页码
	* @param   int        $pagesize         取多少条记录
	* @param   int        $webType         网站类型
	* @return  array
	*/
	function get_url_info($page,$pageSize,$webType = 1)
	{
		$sql = 'SELECT COUNT(*) AS total FROM product_attributes  WHERE  is_delete = 0  
		AND  web_type = '.(int)$webType;
		$page_info = get_page_info($sql,$pageSize,$page);
		$page_url = get_page_url($page,$page_info['page_num']);
		return  array('page_info'=>$page_info,'page_url'=>$page_url);
	}
	/**
	* 得到列表或者其它的产品属性信息
	*
	* @param   string     $type             类型（list为列表 不带搜索,edit代表为编辑）
	* @param   int        $attributes_id    产品属性id
	* @param   int        $start            从那行开始
	* @param   int        $pagesize         取多少条记录
	* @param   int        $webType         网站类型
	* @return  array
	*/
	function  get_products_attributes_info($type,$attributes_id,$start = 0,$pageSize = 10 , $webType = 1)
	{
		if($type == 'list')
		{
			$sql = 'SELECT id,name,add_time ,add_user ,update_time ,update_user  ,is_delete  
			FROM product_attributes  WHERE  is_delete = 0 AND  
			web_type = '.(int)$webType .'  ORDER BY add_user  DESC  LIMIT '.$start.','.$pageSize ;		
		}elseif($type == 'edit')
		{
			$sql = 'SELECT id,name,add_time ,add_user ,update_time ,update_user ,is_delete  
			FROM product_attributes  WHERE  id = '.$attributes_id;
		}
		return $this->product_attributes_m->get_products_attributes_info($sql);
	
	}
	/**
	* ajax改变值
	*
	* @param   int      $attributes_id    属性id
	* @param   int      $change_value    值
	* @param   int      $field           要改变的数据字段
	* @return  int
	*/
	function  change_info($attributes_id ,$change_value,$field)
	{
		$sql = "UPDATE product_attributes   SET $field ='$change_value',modify_status = 1 WHERE id  = $attributes_id  "; 
		return $this->product_attributes_m->change_info($sql);
	}
	/**
	* 修改 
	*
	* @param   int           $attributes_id          产品属性主键
	* @param   string        $name                   产品属性名称
	* @param   string        $webType                网站类型
	* @return  int
	*/
	function update_products_attributes($attributes_id = 0,$name = '',$webType = 1)
	{
		if(!empty($_POST['attributes_id']))
		{
			$sql = "UPDATE product_attributes SET name  ='$name' ,update_time  = '".$_SERVER['REQUEST_TIME']."'
			,update_user  = '".$_SESSION['AName']."',modify_status = 1	WHERE id  = $attributes_id ";
		}else
		{
			$sql = "INSERT INTO  product_attributes (name,add_time,add_user,update_time,update_user , web_type) VALUES ('$name',
			'".$_SERVER['REQUEST_TIME']."','".$_SESSION['AName']."','".$_SERVER['REQUEST_TIME']."','".$_SESSION['AName']."','".$webType."')";	
		}
		
		return $this->product_attributes_m->change_info($sql);
	}


}
?>